
====================
' This file was modified as part of an ASP.NET 2.0 Web project conversion.
' The class name was changed and the class modified to inherit from the abstract base class 
'''/ in file 'App_Code\Migrated\Stub_blog_aspx_cs.cs'.
' During runtime, this allows other classes in your web application to bind and access 
' the code-behind page using the abstract base class.
' The associated content page 'blog.aspx' was also modified to refer to the new class name.
' For more information on this code pattern, please refer to http://go.microsoft.com/fwlink/?LinkId=46995 
====================
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
    ''' <summary>
    ''' Summary description for blog.
    ''' </summary>
    Partial Public Class Migrated_blog
        Inherits blog
        Protected trGroupMenu As System.Web.UI.HtmlControls.HtmlTableRow
        Protected hlGMGroupBulletin As System.Web.UI.WebControls.HyperLink
        Protected hlGMGroupTrash As System.Web.UI.WebControls.HyperLink
        'protected System.Web.UI.WebControls.HyperLink hlConfirmFriends;
        'protected System.Web.UI.WebControls.HyperLink hlPostBlog;
        Protected lblUMBlog As System.Web.UI.WebControls.Label
        Protected lblGMGroupBlog As System.Web.UI.WebControls.Label
        Protected hlUMPostBlog As System.Web.UI.WebControls.HyperLink
        Protected hlUMInbox As System.Web.UI.WebControls.HyperLink
        Protected hlUMSent As System.Web.UI.WebControls.HyperLink
        Protected hlUMGroupBulletin As System.Web.UI.WebControls.HyperLink
        Protected hlUMTrash As System.Web.UI.WebControls.HyperLink
        Protected grpID As Integer = -1
        Protected grp As Group = Nothing
        Protected usr As User = Nothing
        Protected isGroupMode As Boolean = False
        Protected isModerator As Boolean = False
        Protected htPageConstants As New Hashtable()

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            ' this.pageTemplate.PageTitle = PageTitles.BLOG_PAGE;
            ' Auto login from an external link
            'AutoLogin( Request );

            ' init user
            usr = LoggedUser

            If LoggedUser = Nothing Then
                Common.Utils.RedirectToLoginPage(Page)
            End If

            ' init page from XML
            Me.initPageTitles(Constants.BLOG, "", Form1, Nothing, htPageConstants)
            Me.initAdvertisements(Form1, Nothing)

            ' init Tabs
            ucBlogTabs.ActiveTab = 1
            ucBlogTabs.PageName = Constants.BLOG
            grpBlogTabs.ActiveTab = 2
            grpBlogTabs.PageName = Constants.BLOG

            Me.RegisterStartupScript("resizeImages", Constants.RESIZE_BLOG_IMAGE_SCRIPT)
            Me.pageTemplate.onLoadScript = "resizeImages()"

            ' init group
            If Request.Params(Constants.GROUP_PARAM) <> Nothing AndAlso Request.Params(Constants.GROUP_PARAM) <> "" Then
                isGroupMode = True

                Try
                    grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
                Catch
                    Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
                End Try

                grp = Groups.GetGroupByID(grpID)

                If grp = Nothing Then
                    Throw New Exception(Constants.ERROR_MESSAGE_GROUP_DOESNT_EXIST_ERROR)
                End If

                ' check if the logged user is a group member
                If Not grp.Members.Contains(usr.ID) Then
                    Throw New Exception(Constants.ERROR_MESSAGE_ONLY_MEMBER_CAN_VIEW_MESSAGES)
                End If
            End If

            If isGroupMode Then
                ' init page title visibility
                'lblGroupBlogTitle.Visible = true;
                lblBlogTitle.Text = Me.GetPageConstText(htPageConstants, "CONST_GroupBlogTitle_TEXT")
                'hlPostBlog.Text = this.GetPageConstText(htPageConstants, "CONST_PostGroupBlog_TEXT");

                ' init menu to group
                grpBlogTabs.Visible = True
                ucBlogTabs.Visible = False

                hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)
                hlBackToGroup.NavigateUrl = "../" + Constants.GROUP + "?" + Constants.GROUP_PARAM + "=" + grp.ID

                ' init moderator mode
                isModerator = (grp.Uid = usr.ID)

                grpBlogTabs.Moderator = isModerator
            Else
                ' init menu to user
                grpBlogTabs.Visible = False
                ucBlogTabs.Visible = True

                hlBackToGroup.Visible = False
            End If

            If Not IsPostBack Then
                BindGrid()
            End If
        End Sub
        Protected Function CreateDataSource() As ICollection
            usr = LoggedUser

            Dim dt As New DataTable()
            Dim curBlogDate As DateTime
            Dim blogList As ArrayList = Nothing
            Dim blogComments As ArrayList = Nothing
            Dim newBlogComments As ArrayList = Nothing
            Dim nBlogCommentsInTotal As Integer = 0

            If isGroupMode Then
                ' List groups's blogs
                blogList = Messages.GetGroupBlogs(grp.ID)
            Else
                ' List user's blogs
                blogList = Messages.GetUserBlogs(LoggedUser.ID)
            End If

            If blogList.Count = 0 Then
                lblNoBlog.Visible = True
            Else
                lblNoBlog.Visible = False
            End If
            Dim dr As DataRow
            dt.Columns.Add(New DataColumn("BlogID", GetType(Integer)))
            dt.Columns.Add(New DataColumn("Date", GetType(String)))
            dt.Columns.Add(New DataColumn("Time", GetType(String)))
            dt.Columns.Add(New DataColumn("Subject", GetType(String)))
            dt.Columns.Add(New DataColumn("Body", GetType(String)))
            dt.Columns.Add(New DataColumn("CommentsCount", GetType(String)))
            dt.Columns.Add(New DataColumn("CommentsCountVisible", GetType(Boolean)))
            dt.Columns.Add(New DataColumn("CommentsCountNullVisible", GetType(Boolean)))
            dt.Columns.Add(New DataColumn("EditVisibility", GetType(Boolean)))

            If isGroupMode Then
                ' List group blogs
                For Each blog As GroupBlog In blogList
                    dr = dt.NewRow()
                    curBlogDate = blog.DateSent
                    blogComments = Messages.GetGroupBlogEntries(blog.ID)
                    newBlogComments = Messages.GetNotApprovedGroupBlogEntries(grp.ID, blog.ID)
                    nBlogCommentsInTotal = blogComments.Count
                    If isModerator Then
                        nBlogCommentsInTotal += newBlogComments.Count
                    End If

                    dr(0) = blog.ID
                    dr(1) = curBlogDate.DayOfWeek + ", " + Constants.ARR_MONTHS(curBlogDate.Month - 1) + " " + curBlogDate.Day + ", " + curBlogDate.Year
                    dr(2) = curBlogDate.ToShortTimeString()
                    dr(3) = Server.HtmlEncode(blog.Subject)
                    dr(4) = Me.initBlogMessage(blog.Body)
                    If nBlogCommentsInTotal > 0 Then
                        dr(5) = nBlogCommentsInTotal + " " + "Comment"
                        dr(6) = True
                        dr(7) = False
                    Else
                        dr(5) = ""
                        dr(6) = False
                        dr(7) = True
                    End If
                    If nBlogCommentsInTotal > 1 Then
                        dr(5) += "s"
                    End If
                    dr(8) = isModerator

                    dt.Rows.Add(dr)
                Next
            Else
                ' List user's blogs
                For Each blog As Blog In blogList
                    dr = dt.NewRow()
                    curBlogDate = blog.DateSent
                    blogComments = Messages.GetUserBlogEntries(blog.ID)
                    newBlogComments = Messages.GetNotApprovedBlogEntries(blog.ID)
                    nBlogCommentsInTotal = blogComments.Count + newBlogComments.Count

                    dr(0) = blog.ID
                    dr(1) = curBlogDate.DayOfWeek + ", " + Constants.ARR_MONTHS(curBlogDate.Month - 1) + " " + curBlogDate.Day + ", " + curBlogDate.Year
                    dr(2) = curBlogDate.ToShortTimeString()
                    dr(3) = Server.HtmlEncode(blog.Subject)
                    dr(4) = Me.initBlogMessage(blog.Body)
                    If nBlogCommentsInTotal > 0 Then
                        dr(5) = nBlogCommentsInTotal + " " + "Comment"
                        dr(6) = True
                        dr(7) = False
                    Else
                        dr(5) = ""
                        dr(6) = False
                        dr(7) = True
                    End If
                    If nBlogCommentsInTotal > 1 Then
                        dr(5) += "s"
                    End If

                    dr(8) = True
                    dt.Rows.Add(dr)
                Next
            End If
            Dim dv As New DataView(dt)
            Return dv
        End Function

        Protected Sub BindGrid()
            dgMessages.DataSource = CreateDataSource()
            dgMessages.DataBind()
        End Sub

		#region Web Form Designer generated code
        Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
            '
            ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
            '
            InitializeComponent()
            MyBase.OnInit(e)
        End Sub

        ''' <summary>
        ''' Required method for Designer support - do not modify
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
            AddHandler Me.dgMessages.ItemCommand, AddressOf Me.dgMessages_ItemCommand

        End Sub
#End Region

        Private Sub dgMessages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
            Dim btnPushed As LinkButton = DirectCast(e.CommandSource, LinkButton)
            Dim cmd As String = e.CommandName
            Select Case cmd
                Case "ViewComments"
                    If isGroupMode Then
                        Response.Redirect(Constants.VIEW_BLOG_COMMENTS + "?id=" + e.CommandArgument + "&" + Constants.GROUP_PARAM + "=" + grp.ID)
                    Else
                        Response.Redirect(Constants.VIEW_BLOG_COMMENTS + "?id=" + e.CommandArgument)
                    End If
                    Exit Select
                Case "AddComment"
                    If isGroupMode Then
                        Response.Redirect(Constants.POST_BLOG_COMMENT + "?id=" + e.CommandArgument + "&" + Constants.GROUP_PARAM + "=" + grp.ID)
                    Else
                        Response.Redirect(Constants.POST_BLOG_COMMENT + "?id=" + e.CommandArgument)
                    End If
                    Exit Select
                Case "Edit"
                    If isGroupMode Then
                        Response.Redirect(Constants.SEND_BLOG + "?id=" + e.CommandArgument + "&" + Constants.GROUP_PARAM + "=" + grp.ID)
                    Else
                        Response.Redirect(Constants.SEND_BLOG + "?id=" + e.CommandArgument)
                    End If
                    Exit Select
                Case "Remove"
                    If isGroupMode Then
                        ' Delete group blog
                        If isModerator Then
                            Dim grpBlog As GroupBlog = Messages.GetGroupBlogEntry(grp.ID, Convert.ToInt32(e.CommandArgument))
                            grpBlog.Delete()
                            Response.Redirect(Constants.BLOG + "?" + Constants.GROUP_PARAM + "=" + grp.ID)
                        Else
                            Throw New Exception(Constants.ERROR_MESSAGE_ONLY_MODERATOR_CAN_DELETE_BLOG)
                        End If
                    Else
                        Dim blog As Blog = Messages.GetUserBlogEntry(LoggedUser.ID, Convert.ToInt32(e.CommandArgument))
                        blog.Delete()
                        Response.Redirect(Constants.BLOG)
                    End If
                    Exit Select
            End Select
        End Sub

		====================
        ' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
        '    public System.Web.UI.HtmlControls.HtmlForm Form1 {
        Public Overloads Overrides ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
            Get
                Return Migrated_Form1
            End Get
        End Property
        'set { Migrated_Form1 = value; }
    End Class
End Namespace






